package com.bz.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bz.item.service.ItemParamService;
import com.bz.mapper.TbItemParamMapper;
import com.bz.pojo.TbItemParam;
import com.bz.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

@Service
public class ItemParamServiceImpl extends ServiceImpl<TbItemParamMapper, TbItemParam> implements ItemParamService {

    /**
     * 根据商品分类ID查询规格参数模板
     * @param itemCatId
     * @return
     */
    @Override
    public TbItemParam selectItemParamByItemCatId(Long itemCatId) {
        QueryWrapper<TbItemParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(TbItemParam::getItemCatId,itemCatId);
        return this.baseMapper.selectOne(wrapper);
    }

    /**
     * 分页查询所有商品规格参数模板
     * @param page
     * @param rows
     * @return
     */
    @Override
    public PageResult selectItemParamAll(Integer page, Integer rows) {
        QueryWrapper<TbItemParam> queryWrapper = new QueryWrapper<>();
        Page<TbItemParam> pageInfo = PageHelper.startPage(page, rows).doSelectPage(() -> this.baseMapper.selectList(queryWrapper));
        return new PageResult(page,rows,pageInfo.getResult());
    }

    /**
     * 根据商品分类添加规格参数模板
     * @param tbItemParam
     * @return
     */
    @Override
    public Integer insertItemParam(TbItemParam tbItemParam) {
        return this.baseMapper.insert(tbItemParam);
    }

    /**
     * 根据规格参数模板的ID删除数据
     * @param id
     * @return
     */
    @Override
    public Integer deleteItemParamById(Long id) {
        return this.baseMapper.deleteById(id);
    }
}
